var handler_pick

function LocationPickHandle() {
    var scene = viewer.scene;
    var tooltip = new GlobeTooltip(viewer.container);
    if (!handler_pick || handler_pick.isDestroyed()) {
        handler_pick = new Cesium.ScreenSpaceEventHandler(scene.canvas);
        //设置鼠标左键单击回调事件
        var position = null;
        handler_pick.setInputAction(function(e) {
            //首先移除之前添加的点
            removeAllEntities();
            //获取点击位置笛卡尔坐标
            position = getPickPositionGlobe(e.position);
            //将笛卡尔坐标转化为经纬度坐标
            var cartographic = Cesium.Cartographic.fromCartesian(position);
            var longitude = Cesium.Math.toDegrees(cartographic.longitude);
            var latitude = Cesium.Math.toDegrees(cartographic.latitude);
            var height = cartographic.height;
            if (height < 0) {
                height = 0;
            }
            //创建弹出框信息
            $("#locationPickForm").show();
            $("#locationPickX").val(longitude);
            $("#locationPickY").val(latitude);
            $("#locationPickZ").val(height);
            //在点击位置添加对应点
            viewer.entities.add({
                point: {
                    color: Cesium.Color.RED.withAlpha(1),
                    pixelSize: 10,
                    outlineColor: Cesium.Color.WHITE.withAlpha(1)
                },
                position: Cesium.Cartesian3.fromDegrees(longitude, latitude, height + 0.5)
            });
            tooltip.setVisible(false);
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
        //鼠标移动
        handler_pick.setInputAction(function(event) {
            var wp = event.endPosition;
            if (!Cesium.defined(wp)) {
                return;
            }
            if (position == null && !clearTAG) {
                tooltip.showAt(wp, "<p>单击选择位置</p>");
            }else{
                tooltip.setVisible(false);
            }
            var cartesian = getPickPositionGlobe(wp);
            if (!Cesium.defined(cartesian)) {
                return;
            }
        }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
    }
}

//创建描述位置的对话框
function createDescription(Cesium, properties) {
    var simpleStyleIdentifiers = ['经度', '纬度', '高度'];
    var html = '';
    for (var key in properties) {
        if (properties.hasOwnProperty(key)) {
            if (simpleStyleIdentifiers.indexOf(key) !== -1) {
                continue;
            }
            var value = properties[key];
            if (Cesium.defined(value) && value !== '') {
                html += '<tr><td>' + simpleStyleIdentifiers[key] + '</td><td>' + value + '</td></tr>';
            }
        }
    }
    if (html.length > 0) {
        html = '<table class="zebra"><tbody>' + html + '</tbody></table>';
    }
    return html;
}

function LocationPickClear() {
    removeAllEntities();
    position = null;
    // handler_pick ? handler_pick.destroy() : null
    handler_pick.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
    $("#locationPickForm").hide();
    $("#locationPickX").val("")
    $("#locationPickY").val("")
    $("#locationPickZ").val("")
}